home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / compuserve-file-archive / 08 System Utilities / WEDGE.SRC < prev    next >
Text File  |  2019-04-13  |  15KB  |  560 lines

  1. ;*******************************
  2. ;*                             *
  3. ;*  pet dos support            *
  4. ;*                             *
  5. ;*    04-27-79                 *
  6. ;*                             *
  7. ;* copyright (c) 1979,1982     *
  8. ;* commodore business machines *
  9. ;*          inc.               *
  10. ;*                             *
  11. ;*  bob fairbairn              *
  12. ;*                             *
  13. ;*******************************
  14. ;
  15. ;
  16. ;***************************************
  17. ;* this software is furnished for use  *
  18. ;* use in the commodore computer       *
  19. ;* series only.                        *
  20. ;*                                     *
  21. ;* copies thereof may not be provided  *
  22. ;* or made available for use on any    *
  23. ;* other system.                       *
  24. ;*                                     *
  25. ;* the information in this document is *
  26. ;* subject to change without notice.   *
  27. ;*                                     *
  28. ;* no responsibility is assumed for    *
  29. ;* reliability of this software.       *
  30. ;*                                     *
  31. ;* this disclaimer must always be      *
  32. ;* included with this source code      *
  33. ;*                                     *
  34. ;***************************************
  35. ;
  36. ;
  37. ;****************************************
  38. ;* version 5.0 12/16/81-02/10/82        *
  39. ;*    add new commands, allow to work in*
  40. ;*    running program. put volume names *
  41. ;*    in all commands using brackets    *
  42. ;*    only works with basic4.0          *
  43. ;*                                      *
  44. ;*                                      *
  45. ;* version 5.1/64   06/07/82-07/13/82   *
  46. ;*    make work with commodore 64       *
  47. ;*                                      *
  48. ;****************************************
  49. .page
  50. ;
  51. ;basic variables used
  52. ;
  53. bufpt  =$a6            ;cassette (two bytes)
  54. cntdn  =$a5            ;save area
  55. txttab =$2b            ;pointer to basic start
  56. txtptr =$7a            ;pointer to buf
  57. satus  =$90            ;status byte
  58. sa     =$b9            ;secondary address
  59. fa     =$ba            ;primary address
  60. fnlen  =$b7            ;file name length
  61. fnadr  =$bb            ;file name address
  62. eal    =$ae            ;end addr lo
  63. eah    =$af            ;hi
  64. vartab =$2d            ;end of basic pgm.
  65. tmp2   =$c3            ;temp variable
  66. buf    =$0200          ;input buffer
  67. ;
  68. ;program variables
  69. ;
  70. cr     =$0d            ;symbolic carriage return
  71. .page
  72. ;
  73. ;cbm 64  routines used (2.0 basic)
  74. ;
  75. main   =$a48c          ;where called from(main+12)
  76. linprt =$bdcd          ;print line #
  77. clsei  =$f642          ;close a file
  78. loadsp =$ffd5          ;load routine
  79. chrget =$73            ;inputs characters
  80. chrgot =$79            ;get last char
  81. gone   =$a7e6          ; statement exec(ngone+2)
  82. snerr  =$af08          ; syntax error print
  83. chdgot =$e3a8          ;rom copy of chrgot
  84. newstt =$a7ae          ;new statement exec
  85. prt    =$e716          ;print a character
  86. listn  =$ffb1          ;send listen
  87. setmsg =$ff90          ;set kernal messages
  88. secnd  =$ff93          ;send sa
  89. ciout  =$ffa8          ;send character
  90. unlsn  =$ffae          ;un listen
  91. acptr  =$ffa5          ;get a charcater
  92. talk   =$ffb4          ;send talk
  93. openi  =$f3d5          ;open file
  94. ready  =$e386          ;reenter basic
  95. runc   =$a659          ;clear variables and stack
  96. lnkprg =$a533          ;link basic lines
  97. untlk  =$ffab          ;un talk
  98. stxtpt =$a68e          ;set start text pointer
  99. stop   =$ffe1          ;check for stop key
  100. csave  =$e156+3        ;save with address set (basic)
  101. tksa   =$ff96          ;talk secondary address
  102. getin  =$ffe4          ;get a character
  103. .page  'wedge parser'
  104. ;
  105. ;wedge in routine with the
  106. ;command parser and executition
  107. ;
  108. *=$cc00
  109. jmp    gooo
  110. tabhi
  111. .byt   >zz1            ;%        load (non relo)
  112. .byt   >zz1            ;/        load
  113. .byt   >zz1            ;/ token    "
  114. .byt   >zz2            ;^        load/run
  115. .byt   >zz2            ;^ token   "    "
  116. .byt   >zz3            ;_        save
  117. .byt   >zz4            ;>        disk command
  118. .byt   >zz4            ;> token    "     "
  119. .byt   >zz4            ;@          "     "
  120. .byt   >zz5            ;#        change device
  121. .byt   >zz6            ;q        quit
  122. ;
  123. tablo
  124. .byt   <zz1            ;%
  125. .byt   <zz1            ;/
  126. .byt   <zz1            ;/ token
  127. .byt   <zz2            ;^
  128. .byt   <zz2            ;^ token
  129. .byt   <zz3            ;_
  130. .byt   <zz4            ;>
  131. .byt   <zz4            ;> token
  132. .byt   <zz4            ;@
  133. .byt   <zz5            ;#
  134. .byt   <zz6            ;q
  135. ;
  136. ncmd   =9              ;number of main commands
  137. cmd    .byt '%/',$ad,'^',$ae,'_','>',$b1,'@#q',$00
  138. ;commands  % / / ^ ^ _ > > @ # q
  139. ;commands  1 2 3 4 5 6 7 8 9 a b
  140. ;
  141. file   *=*+1           ;data for disk is stored here
  142. file1  *=*+79
  143. svfa   *=*+1           ;save fa
  144. vol    *=*+1           ;volume name
  145. lastch *=*+1           ;last char from chrget
  146. flag   *=*+1           ;save command
  147. msgs   .byt $d,$d,'      dos manager v5.1/071382',$d
  148. .byt   $d, '         by  bob fairbairn',$d
  149. .byt   $d, '(c) 1982 commodore business machines',$d,$0
  150. jump   jmp start       ;overlay for z-page 'chrgot'
  151. .page  'init code      ; vector'
  152. ;
  153. ; init the memory manager (startup comes here)
  154. ;
  155. gooo
  156.        ldx #$02        ;move three bytes
  157. wedge  lda jump,x
  158.        sta chrgot+3,x
  159.        dex
  160.        bpl wedge
  161. ;
  162.        lda fa          ;use current fa for device addr
  163.        sta svfa
  164. ;
  165. ; say hello and exit
  166. ;
  167.        jmp msg         ;print hello (jsr/rts)
  168. ;
  169. ; this is where we come to do the work
  170. ;
  171. start
  172.        sta bufpt       ;save .a, .x
  173.        stx bufpt+1
  174.        tsx             ;activated  call in 'gone'
  175.        lda $0101,x
  176.        cmp #<gone      ;from a running program??
  177.        beq trytwo
  178.        cmp #<main      ;from direct mode??
  179.        bne notcmd
  180. trytwo lda $0102,x
  181.        cmp #>gone      ;program?
  182.        beq findit
  183.        cmp #>main      ;direct?
  184.        bne notcmd
  185. findit lda bufpt       ;get the command back
  186.        ldx #ncmd-1
  187. findc  ;find the command
  188.        cmp cmd,x
  189.        beq call10
  190.        dex
  191.        bpl findc
  192. ;
  193. notcmd
  194.        lda bufpt       ;restore regs
  195.        ldx bufpt+1
  196.        cmp #':         ;complete chrgot
  197.        bcs strts
  198.        jmp chrgot+7
  199. strts  jmp chrgot+17   ;to the end of chrgot
  200. ;
  201. call10
  202.        stx cntdn       ;save index
  203.        sta flag        ;save the command for later
  204.        jsr rdfile      ;get the filename and length
  205.        ldx cntdn       ;restore index
  206.        lda #<file      ;set filename address
  207.        sta fnadr
  208.        lda #>file
  209.        sta fnadr+1
  210.        lda svfa        ;set primary address
  211.        sta fa
  212. ;
  213. callit
  214.        lda tabhi,x     ;found command...go there
  215.        pha
  216.        lda tablo,x
  217.        pha
  218.        rts
  219. .pag
  220. ;
  221. ;main action routine for wedge commands '>@'
  222. ;
  223. doit
  224.        tya             ;.y has fnlen
  225.        beq rderr       ;no data so read e. c.
  226. ;
  227.        ldx #ncmd       ;now check for sub-commands
  228. chksub
  229.        lda cmd,x
  230.        beq chklst      ;ran out...
  231.        cmp file        ;is this a command?
  232.        beq fndsub      ;yes...
  233.        inx
  234.        bpl chksub
  235. ;
  236. chklst ;not a sub-command
  237.        lda file        ;is this a dir command
  238.        cmp #'$
  239.        beq dodir       ;directory stuff
  240.        jmp notdir      ;disk commands
  241. ;
  242. ;
  243. fndsub ;found sub command
  244.        dec fnlen       ;setup and go there
  245.        lda #<file1
  246.        sta fnadr
  247.        lda #>file1
  248.        sta fnadr+1
  249.        jmp callit
  250. .page  'disk cmd & e. c.'
  251. ;
  252. ; send command to disk
  253. ;
  254. notdir
  255.        lda fa          ;device address
  256.        jsr listn
  257.        lda #$6f
  258.        sta sa
  259.        jsr secnd       ;send secondary addr
  260.        ldy #0
  261. bump   lda file,y
  262.        jsr ciout
  263.        iny
  264.        cpy fnlen
  265.        bcc bump        ;more
  266. ;
  267.        jsr unlsn       ;un listen
  268.        jmp wg998
  269. ;
  270. ; read the error channel
  271. ;
  272. rderr
  273.        lda fa          ;device address
  274.        jsr talk
  275.        lda #$6f        ;command channel sa
  276.        sta sa
  277.        jsr tksa        ;send sa talk style
  278. wg140  jsr acptr       ;get byte from disk
  279.        cmp #cr
  280.        beq wg130
  281.        jsr prt         ;print byte to screen
  282.        jmp wg140       ;loop for more
  283. wg130  jsr prt         ;print cr
  284.        jsr untlk       ;un talk
  285. wg998  jmp chrgot      ;done with cmd
  286. .page  'directory read'
  287. ;
  288. ;print the directory '@$0:*'
  289. ;
  290. dodir
  291.        lda #$60        ;secondary addr
  292.        sta sa
  293.        jsr openi       ;open the file
  294.        lda fa          ;get primary address
  295.        jsr talk
  296.        lda sa          ;get secondary address
  297.        jsr tksa
  298. .ski
  299.        lda #0
  300.        sta satus       ;set status to 0
  301.        ldy #$03        ;loop three times
  302. wg220  sty fnlen       ;save new count
  303.        jsr acptr
  304.        sta tmp2
  305.        jsr acptr
  306.        sta tmp2+1
  307.        ldy satus       ;check status
  308.        bne wg230
  309.        ldy fnlen       ;more to do?
  310.        dey
  311.        bne wg220       ;not done yet
  312.        ldx tmp2
  313.        lda tmp2+1
  314.        jsr linprt      ;print line number
  315.        lda #$20        ;print a space
  316.        jsr prt
  317. wg250  jsr acptr
  318.        ldx satus
  319.        bne wg230       ;bad
  320.        cmp #0          ;eol
  321.        beq wg240
  322.        jsr prt
  323. ;check for stop key and pause
  324.        jsr stop        ;stop key
  325.        beq wg230       ;yes...
  326.        jsr getin       ;get a char from keyboard
  327.        beq wg250       ;nothing...
  328.        cmp #$20        ;space bar for pause?
  329.        bne wg250       ;no...
  330. wg255  jsr getin       ;any key starts
  331.        beq wg255
  332.        bne wg250       ;(jmp)
  333. ;
  334. wg240  lda #cr
  335.        jsr prt
  336.        ldy #$02        ; do twice
  337.        jmp wg220
  338. ;
  339. ;close floppy and return
  340. ;
  341. wg230  jsr clsei       ;close file
  342.        lda #cr         ;print a return
  343.        jsr prt
  344.        jmp chrgot      ;return
  345. .page  'file load/run'
  346. ;
  347. ;    load or load and run a file
  348. ;  (fnlen is set and the name is in file)
  349. ;  %filename ...... load (non relocating)
  350. ;  /filename ...... load
  351. ;  ^filename ...... load/run
  352. ;
  353. runr
  354. load
  355.        ldx txttab      ;set pointer for auto locate
  356.        ldy txttab+1
  357.        lda flag        ;set type of load
  358.        cmp #'%
  359.        bne load0
  360.        lda #1
  361.        .byt $2c        ;skip2
  362. load0  lda #0
  363.        sta sa
  364.        lda #$0
  365.        jsr loadsp      ;load a program
  366.        bcs lderr       ;trouble in river city
  367.        lda flag        ;load type
  368.        cmp #'%         ;is it an absolute load
  369.        beq load1       ;yes
  370.        lda eah         ;set basic's pointers
  371.        sta vartab+1
  372.        lda eal
  373.        sta vartab
  374.        jsr runc        ;fix pointers
  375.        jsr lnkprg      ;fix links
  376.        lda flag        ;check for load or run
  377.        cmp #$ad        ;load command is / (token)
  378.        beq load1       ;yes...load only
  379.        cmp #'/         ;load command is /
  380.        bne wg300       ;no...load/run
  381. load1  jmp ready       ;load return to basic
  382. wg300  lda #$00        ;no kernal messages
  383.        jsr setmsg
  384.        jsr stxtpt      ;set txtptr for run
  385.        jmp newstt      ;run program
  386. lderr  ;load error
  387.        jmp ready
  388. .page  'quit, save, change'
  389. ;
  390. ; quit command '@q'
  391. ;
  392. quit
  393.        ldx #$02
  394. rest   ;restore 'chrget'
  395.        lda chdgot+3,x
  396.        sta chrgot+3,x
  397.        dex
  398.        bpl rest
  399.        jmp ready
  400. ;
  401. ;save command '_filename'
  402. ;
  403. save   ;save a file
  404.        jsr csave       ;call basic save routine just past parsing
  405.        jmp rderr       ;read thee ec after save
  406. ;
  407. ; change the default device number '@#9'
  408. ;
  409. chgdev
  410.        ldy fnlen
  411.        lda file,y
  412.        and #$0f        ;convert ascii to binary
  413.        sta svfa
  414.        dey
  415.        beq chg10       ;only one number
  416. ;
  417.        lda file,y
  418.        and #$0f
  419.        tay             ;use first digit as count
  420.        beq chg10
  421.        lda svfa
  422.        clc
  423. chg05  adc #10         ;add 10 for each count
  424.        dey
  425.        bne chg05
  426.  sta svfa ;save result
  427. chg10
  428.        jmp chrgot
  429. .page  'subroutines'
  430. ;
  431. ; read filename string from command
  432. ; and place it into file string
  433. ;
  434. rdfile
  435.        ldy #0
  436.        jsr chrget
  437.        tax
  438.        bne rd05        ;more to do...
  439.        jmp setlen      ;done...
  440. rd05   lda #$60        ;do not skip blanks or call me chrget
  441.        sta chrgot+3
  442.        lda txtptr      ;save pointer to data
  443.        pha
  444.        lda txtptr+1
  445.        pha
  446.        txa             ;put first char into .a
  447. rd10   cmp #'"         ;look for quote
  448.        beq rd20
  449.        jsr chrget      ;get next character
  450.        bne rd10
  451.        pla             ;did not find quote (read all of line)
  452.        sta txtptr+1    ;restore pointer
  453.        pla
  454.        sta txtptr
  455.        jsr chrgot      ;get first character on line
  456.        ldx #0          ;file name length count
  457.        cmp #'"         ;looking at quote?
  458.        beq fill        ;yes...(must be when running)
  459.        ldx #>buf       ;if in direct mode then ok
  460.        cpx txtptr+1
  461.        bne filer1      ;must have a quote
  462.        ldx #0
  463.        beq fill10      ;(branch)
  464. rd20   pla             ;found quote do our thing
  465.        pla
  466.        ldx #0
  467. ;
  468. fill
  469.        jsr chrget
  470.        beq setlen
  471. fill10
  472.        cmp #'"         ;end quote?
  473.        beq setlen
  474.        cmp #'=         ;filename start
  475.        beq fill20
  476.        cmp #':         ;filename start
  477.        bne storit
  478. fill20
  479.        ldx #$ff        ;do not count
  480. storit
  481.        cmp #'[         ;start vol stuff?
  482.        beq fill30      ;yes...
  483. stor10
  484.        sta file,y
  485.        sta lastch
  486.        inx
  487.        iny
  488.        bpl fill
  489. ;
  490. fill30
  491.        jsr chrget      ;get vol name
  492.        beq filer1      ;required
  493.        sta vol         ;save it
  494.        jsr chrget      ;get closing delimiter
  495.        beq filer1      ;must be there??...
  496.        cmp #']
  497.        bne filer1      ;wrong delimiter....
  498. ;
  499.        cpx #16         ;see if name is too long
  500.        bcs filer1
  501.        lda lastch      ;if last is * then fill ?
  502.        cmp #'*
  503.        bne filspc
  504.        dey             ;do not put in the *
  505.        dex
  506.        lda #'?
  507.        .byt $2c
  508. filspc lda #$20        ;else fill with space
  509. filpat
  510.        cpx #15         ;are we done yet ?
  511.        bcs filend      ;yes...
  512.        sta file,y
  513.        iny
  514.        inx
  515.        bpl filpat
  516. filend
  517.        lda vol         ;put in the volume name
  518.        bne stor10      ;branch
  519. ;
  520. filer1 ;blow off to syntax error
  521.        ldx #$4c        ;restore chrgot
  522.        stx chrgot+3
  523.        jmp snerr
  524. ;
  525. setlen
  526.        sty fnlen       ;save length
  527.        ldx #$4c        ;restore chrgot
  528.        stx chrgot+3
  529. ;
  530.        jsr chrgot      ;throw away the rest of the line
  531.        beq setrts
  532. setclr
  533.        jsr chrget
  534.        bne setclr
  535. ;
  536. setrts ;done
  537.        rts
  538. ;
  539. ;
  540. ; print the sign on msg
  541. ;
  542. msg
  543.        ldx #$00
  544. outlp  lda msgs,x
  545.        beq msgd
  546.        jsr prt
  547.        inx
  548.        bne outlp
  549. msgd   rts
  550. ;
  551. ;these must be after the definitions
  552. ;
  553. zz1    =load-1         ;load a program
  554. zz2    =runr-1         ;run a program
  555. zz3    =save-1         ;save a program
  556. zz4    =doit-1         ;> call
  557. zz5    =chgdev-1       ;change device number
  558. zz6    =quit-1         ;leave dos support
  559. .end
  560.